- /* sxfxsmul.cpp by K.Tsuru */
- // function ID = 509 BRADIX
- /*******************************************************************
- SDecimal class
- Provides the multiplication of SDecimal and a short integer together.
- result = m*x, x <= ULONG_MAX/BRADIX
- ********************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* const func = "XsMult";
- void XsMult(const SDecimal& m, ulong x, SDecimal& result){
- if( !m.Sign() || (x == 0) ){
- result.SetZero(); return;
- }
- if(x == 1){ result = m; return; }
- if(x > m.SlOpMaxValue()) m.SetError(m.OUT_OF_RANGE, func, 509);
- if( result.figure.size() != m.figure.size() ) m.SetError(m.SYNTAX_ERR, func, 509);
-
- uint rh = m.aHead, rt = m.aTail;
- fType* rv = result.figure.Elements();
- const fType* mv = m.ReadFigures();
- #ifndef NDEBUG
- result.figure[rh];
- #endif
- ulong w = 0;
- //"rt" must be casted as int considering the case of rt==0.
- int i;
- for(i = (int)rh; i >= (int)rt; i--) {
- w += (ulong)mv[i] * x;
- rv[i] = fType(w & BRADIX1); // = w%BRADIX
- w >>= BRADIX_BITS; // w /= BRADIX;
- }
- if(w){ //It proceeds the carry. It can be possible that w >= BRADIX.
- for( ; w && (i >= 0) ; i--){
- rv[i] = fType(w & BRADIX1);
- w >>= BRADIX_BITS;
- }
- if(w) m.SetError(m.OVERFLOW_ERR, func, 509);
- rt = i+1;
- }
- //Clear the outside of the above roop.
- if(result.aHead > rh) result.figure.clear(rh+1, result.aHead);
- if(result.aTail < rt) result.figure.clear(result.aTail, rt-1); // rt > 0
- //It decides the figure position.
- result.aTail = rt;
- while(!rv[rh]) rh--;
- result.aHead = rh;
- result.SetSign( m.Sign() ); // result != 0
- #ifndef NDEBUG
- result.figure(rt); result.figure(rh);
- #endif
- }
sxfxsmul.cpp : last modifiled at 2017/03/13 14:32:02(1,741 bytes)
created at 2015/12/22 16:09:56
The creation time of this html file is 2017/10/27 15:45:59 (Fri Oct 27 15:45:59 2017).